package com.vicente.managerdemo.common;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author 李学照
 * @version 1.0
 * @date 2020/3/26
 * @desc
 */

@Data
@NoArgsConstructor
@Component
public class ResultBean {
    public static Integer SUCCESS_CODE = 100;
    public static Integer FAIL_CODE = 101;
    public static Integer ERROR_CODE = 102;
    public static Integer NOT_AUTHC_CODE = 600001;
    public static String SUCCESS_MESSAGE = "处理请求成功";
    public static String FAIL_MESSAGE = "处理请求失败";
    public static String ERROR_MESSAGE = "未知异常";

    private Integer respCode;
    private String respMessage;
    private Object data;

    public ResultBean(Integer respCode, String respMessage, Object data) {
        this.respCode = respCode;
        this.respMessage = respMessage;
        this.data = data;
    }

    public static ResultBean getSuccess(Object data){
        return new ResultBean(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static ResultBean getSuccess(){
        return new ResultBean(SUCCESS_CODE, SUCCESS_MESSAGE, null);
    }

    public static ResultBean getSuccess(Integer sucCode, String sucMsg){
        return new ResultBean(sucCode, sucMsg, null);
    }

    public static ResultBean getFail(Object data){
        return new ResultBean(FAIL_CODE, FAIL_MESSAGE, data);
    }

    public static ResultBean getFail(String errorMsg){
        return new ResultBean(FAIL_CODE, errorMsg, null);
    }

    public static ResultBean getFail(Integer errorCode, String errorMsg){
        return new ResultBean(errorCode, errorMsg, null);
    }

    public static ResultBean gerError(){
        return new ResultBean(FAIL_CODE, ERROR_MESSAGE, "{}");
    }

    public static ResultBean gerError(Object obj){
        return new ResultBean(FAIL_CODE, ERROR_MESSAGE, obj.toString());
    }
}
